home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 9 / Night Owl CD-ROM (NOPV9) (Night Owl Publisher) (1993).ISO / 009a / snpd0493.zip / CERRINST.ASM < prev    next >
Assembly Source File  |  1993-04-05  |  3KB  |  101 lines

  1.         PAGE ,132
  2.  
  3. ;  Install an Interrupt 24 (DOS critical error exception) handler
  4. ;
  5. ;  Public domain by Bob Stout
  6. ;
  7. ;  Requires MASM 5.1 or later or equivalent
  8. ;
  9. ;  Assemble with:       MASM /Mx /z ...
  10. ;                       TASM /jMASM /mx /z ...
  11.  
  12. %       .MODEL  memodel,C               ;Add model support via command
  13.                                         ;line macros, e.g.
  14.                                         ;MASM /Dmemodel=LARGE
  15.  
  16.         .DATA?
  17.  
  18.         PUBLIC cedevdvr, cetype, ceerror, cereturn
  19. _origvec        dd      ?
  20. _newvec         dd      ?
  21. cedevdvr        dd      ?
  22. cetype          dw      ?
  23. ceerror         dw      ?
  24. cereturn        db      ?
  25.  
  26.         .CODE
  27.  
  28. ;
  29. ;  This is our actual ISR
  30. ;
  31. myint24:
  32.         push    ds                      ;save registers which may be
  33.         push    es                      ;required in case "Retry" is
  34.         push    bx                      ;selected
  35.         push    cx
  36.         push    dx
  37.         push    si
  38.         push    di
  39.         push    bp
  40.         mov     word PTR cedevdvr,si    ;save device driver header address
  41.         mov     word PTR cedevdvr+2,bp
  42.         mov     cetype,ax               ;save error type information
  43.         mov     ceerror,di              ;save error code information
  44.         call    far PTR _newvec         ;call our handler
  45.         mov     al,cereturn             ;set up return code (abort, retry...)
  46.         pop     bp                      ;restore necessary registers
  47.         pop     di
  48.         pop     si
  49.         pop     dx
  50.         pop     cx
  51.         pop     bx
  52.         pop     es
  53.         pop     ds
  54.         iret
  55.  
  56. ;
  57. ;  Call this to install  our ISR
  58. ;
  59. ;  void (_far *)() ins24(unsigned short segm, unsigned short offs);
  60. ;  void (_far *)() ins24((void _far *handler)());
  61. ;
  62. ;  Paramters (option 1) - 1 : Segment of handler
  63. ;                         2 : Offset of handler
  64. ;
  65. ;  Paramters (option 2) - 1 : Address of handler
  66. ;
  67. ;  Returns pointer to old handler
  68. ;
  69. ins24   PROC    USES AX BX DS ES, segm:WORD, offs:WORD
  70.         mov     ax,3524h                ;get old vector...
  71.         int     21h
  72.         mov     word PTR _origvec,bx
  73.         mov     word PTR _origvec+2,es  ;...and save it
  74.         mov     ax,offs                 ;load handler offset...
  75.         mov     word PTR _newvec,ax
  76.         mov     ax,segm                 ; & segment into _newvec
  77.         mov     word PTR _newvec+2,ax
  78.         push    cs                      ;get myint24 segment in DS
  79.         pop     ds
  80.         mov     dx, OFFSET myint24      ;install myint24 in int 24h
  81.         mov     ax,2524h                ;  into Interrupt 24h
  82.         int     21h
  83.         mov     ax,word PTR _origvec
  84.         mov     dx,word PTR _origvec+2
  85. ins24   ENDP
  86.  
  87. ;
  88. ;  Call this to uninstall our ISR
  89. ;
  90. ;  void redo24(void);
  91. ;
  92. redo24  PROC    USES AX BX DS
  93.         mov     dx, word PTR _origvec   ;restore original vector
  94.         mov     ds, word PTR _origvec+2
  95.         mov     ax,2524h
  96.         int     21h
  97.         ret
  98. redo24  ENDP
  99.  
  100.         end
  101.